package test

import (
	"github.com/go-martini/martini"
	"github.com/martini-contrib/render"
	// "io/ioutil"
	// "io"
	// "fmt"
	"net/http"
	"server/lib/Imartini"
	"server/lib/image"
	"server/lib/upload"
)

func upload_image(r render.Render, log *Imartini.Mlog) {
	r.HTML("test/mapro/update_product.html", map[string]interface{}{
		"title": "请上传图片",
	})
}

func post_image(res http.ResponseWriter, req *http.Request, c martini.Context, g Imartini.G) (string, error) {
	// f, _, err := req.FormFile("UpLoadFile")
	// if err == nil {
	//  defer f.Close()
	//  b, _ := ioutil.ReadAll(f)
	//  str := fmt.Sprintf("%s", b)
	//  mp.Update_product(str)
	// } else {
	//  mlog.Printf("%s", err)
	// }
	Imartini.AddLog(g, "uploadfile")
	path, err := upload.Save(req, "UpLoadFile")
	image.Thumbnail(path, path, 320, 320)
	return path, err
}
